package com.aaa.dem1101.Synchronized;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2022/11/1  13:40
 */
public class MyTicket implements Runnable{
    private int ticket=100;
    private static Object lock=new Object();
    @Override
    public void run() {
        while (true){
            synchronized (lock) {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖票一张,剩余：" + --ticket);
                } else {
                    break;
                }
            }
        }
    }
}
